package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * 游记推荐
 */
@Getter@Setter@ToString
public class TravelCommend extends BaseDomain {
    public static final Integer TYPE_WEEK = 1;//每周推荐
    public static final Integer TYPE_MONTH = 2;//每月推荐
    public static final Integer TYPE_STRATEGY = 3;//攻略推荐
    private Travel travel;//游记

    private String title;//标题

    private String subTitle;//副标题

    private String coverUrl;//背景图片

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date schedule;//推荐时间

    private Integer type = TYPE_WEEK;//推荐类型

    public String getTypeName(){
        String typeName = "每周推荐";
        if (TYPE_MONTH.equals(typeName)) {
            typeName = "每月推荐";
        }else if (TYPE_STRATEGY.equals(typeName)){
            typeName = "攻略推荐";
        }
        return typeName;
    }

    public String getJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        if (travel != null) {
            map.put("travelId",travel.getId());
        }
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        //将时间转化为指定格式的字符串
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        map.put("schedule",format.format(schedule));
        map.put("type",type);
        return JSONUtil.toJSONString(map);
    }
}